import './utils/utils'
import './utils/http'
// app.js
App({
  globalData: {},
  onLaunch() {
    // 读取token
    this.getToken()
    this.getRefreshToken()

  },
  // 从本地获取到token  存到全局数据中
  getToken() {
    wx.getStorage({
      key: 'token',
      success: (res) => {
        this.token = res.data
      }
    })
  },

  // 从本地获取到refreshToken  存到全局数据中
  getRefreshToken() {
    wx.getStorage({
      key: 'refreshToken',
      success: (res) => {
        this.refreshToken = res.data
      }
    })
  },
  setToken(token, refreshToken) {
    // 将token存到本地
    wx.setStorageSync('token', `Bearer ${token}`)
    // 将token存到全局
    this.token = `Bearer ${token}`

    // 将refreshToken存到本地
    wx.setStorageSync('refreshToken', `Bearer ${refreshToken}`)
    // 将refreshToken存到全局
    this.refreshToken = `Bearer ${refreshToken}`

  }

})
